package com.dnake.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dnake.Constant;
import com.dnake.entity.EventSettingBean;
import com.dnake.panel.BuildConfig;
import com.dnake.panel.R;
import com.dnake.utils.AppUtils;
import com.wx.android.common.util.SharedPreferencesUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.Bind;
import butterknife.ButterKnife;
import me.yokeyword.fragmentation.SupportFragment;

/**
 * @author haoyuliu
 * @since 2017/7/18
 */

public class InformationFragment extends SupportFragment {
    @Bind(R.id.tv_sn)
    TextView tvSn;
    @Bind(R.id.tv_rom)
    TextView tvRom;
    @Bind(R.id.tv_apk)
    TextView tvApk;
    @Bind(R.id.tv_device_type)
    TextView tvDeviceType;
    @Bind(R.id.tv_video)
    TextView tvVideo;
    @Bind(R.id.tv_lock_type)
    TextView tvLockType;
    @Bind(R.id.tv_lock_status)
    TextView tvLockStatus;
    @Bind(R.id.tv_network)
    TextView tvNetwork;
    private View mView;

    public static InformationFragment newInstance() {
        return new InformationFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_device_info, container, false);
        ButterKnife.bind(this, mView);
        initView();
        return mView;
    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    private void initView() {
        tvSn.setText(AppUtils.getMacAddress());
        tvRom.setText( android.os.Build.VERSION.RELEASE);
        tvApk.setText(BuildConfig.VERSION_NAME);
        if (SharedPreferencesUtils.getBoolean(Constant.SP_VIDEO_STATUS)){
            tvVideo.setText("开启");
        }
        if (SharedPreferencesUtils.getBoolean(Constant.SP_LOCK_TYPE)){
            tvLockType.setText("磁力锁");
            if (SharedPreferencesUtils.getBoolean(Constant.SP_LOCK_STATUS)){
                tvLockStatus.setText("开启");
            }else {
                tvLockStatus.setText("关闭");
            }
        }else {
            tvLockType.setText("电控锁");
            tvLockStatus.setText("关闭");
        }


    }

    @Override
    public boolean onBackPressedSupport() {
        return super.onBackPressedSupport();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventSetting(EventSettingBean eventBusBean) {
        if (eventBusBean.getCode() == Constant.EVENTBUS_INFORMATION) {
            if ("1".equals(eventBusBean.getName())) {

            } else if ("2".equals(eventBusBean.getName())) {

            } else if ("3".equals(eventBusBean.getName())) {

            }
        }
    }

    @Override
    public void onStop() {
        super.onStop();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
